package cn.demomaster.quickpicturer.view;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;

import java.io.File;

import cn.demomaster.quickpicturer.PhotoView;
import cn.demomaster.quickpicturer.R;
import cn.demomaster.quickpicturer.model.ImageInfo;


/**
 * Squirrel桓
 * 2018/8/25
 */
public class SimpleImageFragment extends Fragment {
    View contentView;
    PhotoView pv_image;
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        contentView = inflater.inflate(R.layout.fragment_layout_preview, null);
        pv_image = contentView.findViewById(R.id.pv_image);
        return contentView;
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUI();
    }

    private void refreshUI() {
        Bundle bundle = getArguments();
        if (bundle != null && bundle.containsKey("image")) {
            ImageInfo imageInfo = bundle.getParcelable("image");
            if (imageInfo!=null) {
                if (imageInfo.isLocalFile()) {
                    Glide.with(getContext()).load(imageInfo.getUri()).into(pv_image);
                } else {
                    Glide.with(getContext()).load(imageInfo.getUrl()).into(pv_image);
                }
            }
        }
    }
}